import React, { Component } from "react";
import { connect } from "react-redux";
import { incrementAsync, increment, decrement } from "../../redux/action/count";
class Count extends Component {
  handleCount = (data) => {
      const {increment,decrement,incrementAsync} = this.props;
    switch (data) {
      case 1:
        increment(1);
        break;
      case 2:
        decrement(1);
        break;
      case 3:
        incrementAsync(1,500);
        break;

      default:
        break;
    }
  };
  render() {
    return (
      <div>
        <h2>当前的count和为{this.props.count},当前总人数为{this.props.persons}</h2>
        <button
          onClick={() => {
            this.handleCount(1);
          }}
        >
          +
        </button>
        <button
          onClick={() => {
            this.handleCount(2);
          }}
        >
          -
        </button>
        <button
          onClick={() => {
            this.handleCount(3);
          }}
        >
          异步加
        </button>
      </div>
    );
  }
}
export default connect((state) => ({ count: state.count,persons:state.persons.length }), { increment,decrement,incrementAsync})(Count);
